package logic

import (
	"context"
	"zhihu/zhihu_rpc/zhihurpcclient"

	"zhihu/api/internal/svc"
	"zhihu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PushTroubleLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPushTroubleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushTroubleLogic {
	return &PushTroubleLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PushTroubleLogic) PushTrouble(req *types.PushTroubleRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	trouble, err := l.svcCtx.ZhiHuRpc.PushTrouble(l.ctx, &zhihurpcclient.PushTroubleRequest{
		Id:      int64(req.UserId),
		Title:   req.Title,
		Content: req.Content,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "问题发布成功",
		Data:    trouble,
	}, nil
}
